This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.
source("tianfengRwrappers.R")
# library(future)
# plan("multiprocess",workers = 8)
CA_dataset2 <- readRDS("CA_dataset2.rds")
CA_dataset1 <- readRDS("CA_dataset1.rds")
human_coronary <- readRDS("human_coronary.rds")
Idents(human_coronary) <- human_coronary$samples
human_coronary <- RenameIdents(human_coronary,'1' = 'sample1','2' = 'sample2','3' = 'sample3','4' = 'sample4')
human_coronary$samples <- Idents(human_coronary)
Idents(human_coronary) <- human_coronary$Classification1
ds2 <- readRDS("ds2.rds")
#sample info
ggsave("dataset2_sampleinfo.svg",plot = umapplot(CA_dataset2, split.by = "sample"),
device = svg, width = 25, height = 5)
ggsave("dataset1_sampleinfo.svg",plot = umapplot(CA_dataset1, split.by = "orig.ident"),
device = svg, width = 15, height = 5)
ggsave("dataset0_sampleinfo.svg",plot = umapplot(human_coronary, split.by = "samples"),
device = svg, width = 20, height = 5)
dataset2
svg(paste0("CA_dataset2_supp","_markers.svg"), height = 10, width = 15)
dhm2(CA_dataset2_markers$gene, CA_dataset2, genes_to_show$gene,"CA_dataset2_supp")
dev.off()
null device
1
dataset1
svg(paste0("CA_dataset1_supp","_markers.svg"), height = 10, width = 15)
dhm2(CA_dataset1_markers$gene, CA_dataset1, genes_to_show$gene,"CA_dataset1_supp")
dev.off()
null device
1
dataset0
human_coronary_markers <- FindAllMarkers(human_coronary, logfc.threshold = 0.5, min.diff.pct = 0.3, only.pos = T)
Calculating cluster FB
Calculating cluster Macrophage
Calculating cluster EC
Calculating cluster SMC
Calculating cluster T cell
Calculating cluster B cell
Calculating cluster Neuron
Calculating cluster Plasma
human_coronary_markers <- human_coronary_markers[human_coronary_markers$pct.1>0.7,] %>% group_by(cluster)
genes_to_show <- human_coronary_markers %>% group_by(cluster) %>% slice_max(n = 5, order_by = avg_logFC)
svg(paste0("human_coronary_supp","_markers.svg"), height = 10, width = 15)
dhm2(human_coronary_markers$gene, human_coronary, genes_to_show$gene,"human_coronary_supp")
dev.off()
RStudioGD
2
Idents(human_coronary) <- human_coronary$conditions
sp1 <- subset(human_coronary, idents = "sample1")
sp2 <- subset(human_coronary, idents = "sample2")
sp3 <- subset(human_coronary, idents = "sample3")
sp4 <- subset(human_coronary, idents = "sample4")
prop_mat <- cbind(prop.table(table(sp1$Classification1)),prop.table(table(sp2$Classification1)))
prop_mat2 <- cbind(prop.table(table(sp3$Classification1)),prop.table(table(sp4$Classification1)))
prop_mat <- cbind(prop_mat, prop_mat2)
colnames(prop_mat) <- levels(Idents(human_coronary))
plot_data = melt(prop_mat)
colnames(plot_data) = c('cell type','position','proportion')#修改每一列的名称
ggplot(plot_data, aes(x = `cell type`, y = proportion, fill = position)) +
geom_bar(stat = 'identity', position = "dodge", width=0.5) + theme_bw()
prop_plot <- ggplot(plot_data, aes(x = `cell type`, y = proportion, fill = position)) +
geom_bar(stat = 'identity', position = "dodge", width=0.7) + coord_cartesian(ylim = c(0,0.3))+
theme_bw() + scale_y_continuous(expand = c(0,0)) + scale_fill_manual(values = colors_list[3:6]) +theme(
axis.title.x = element_text(size = 15), axis.text.x = element_text(size = 15, colour = "black"),
axis.title.y = element_text(size = 15), axis.text.y = element_text(size = 15, colour = "black"),
legend.text = element_text(size = 20), legend.title = element_blank(), panel.grid = element_blank())
ggsave("human_coronary_prop.svg", device = svg, plot = prop_plot, width = 12, height = 6)
fea <- read.csv("./datatable/AC_features.csv")
ggobj <- multi_featureplot(fea$Feature[1:16],ds2_AC,labels = "",label = F)
ggsave("ACpretrain_features.png", device = png, plot = ggobj, width = 8, height = 8)
fea <- read.csv("./datatable/PA_features.csv")
ggobj <- multi_featureplot(fea$Feature[1:16],ds2_PA,labels = "",label = F)
ggsave("PApretrain_features.png", device = png, plot = ggobj, width = 8, height = 8)
fea <- read.csv("./datatable/ACtrain_features.csv")
ggobj <- multi_featureplot(fea$Feature[1:16],ds2_AC,labels = "",label = F)
ggsave("ACmodel_features.png", device = png, plot = ggobj, width = 8, height = 8)
fea <- read.csv("./datatable/PAtrain_features.csv")
ggobj <- multi_featureplot(fea$Feature[1:16],ds2_PA,labels = "",label = F)
ggsave("PAmodel_features.png", device = png, plot = ggobj, width = 8, height = 8)
fea <- read.csv("./datatable/ds2_features.csv")
ggobj <- multi_featureplot(fea$Feature[1:16],ds2,labels = "",label = F)
ggsave("ds2model_features.png", device = png, plot = ggobj, width = 8, height = 8)
fea <- read.csv("./datatable/ds0_features.csv")
ggobj <- multi_featureplot(fea$Feature[1:16],ds0,labels = "",label = F)
ggsave("ds0model_features.png", device = png, plot = ggobj, width = 8, height = 8)
bst_model <- readRDS("ds2_model.rds")
ds2_data <- get_data_table(ds2, highvar = F, type = "data")
Idents(ds2) <- ds2$seurat_clusters
Idents(ds0) <- ds0$seurat_clusters
temp <- get_data_table(ds0, highvar = F, type = "data")
ds0_data <- matrix(data=0, nrow = length(rownames(ds2_data)), ncol = length(colnames(temp)),
byrow = FALSE, dimnames = list(rownames(ds2_data),colnames(temp)))
for(i in intersect(rownames(ds2_data), rownames(temp))){
ds0_data[i,] <- temp[i,]
}
rm(temp)
ds0_label <- as.numeric(as.character(Idents(ds0)))
colnames(ds0_data) <- NULL
ds0_test_data <- list(data = t(as(ds0_data,"dgCMatrix")), label = ds0_label)
ds0_test <- xgb.DMatrix(data = ds0_test_data$data,label = ds0_test_data$label)
#预测结果
predict_ds0_test <- predict(bst_model, newdata = ds0_test)
predict_prop_ds0 <- matrix(data=predict_ds0_test, nrow = length(levels(Idents(ds2))),
ncol = ncol(ds0), byrow = FALSE,
dimnames = list(levels(Idents(ds2)),colnames(ds0)))
## 得到分群结果
ds0_res <- apply(predict_prop_ds0,2,func,rownames(predict_prop_ds0))
Idents(ds0) <- factor(ds0_res,levels = c(0:4))
umapplot(ds0)
ds0$supclustering <- Idents(ds0) #保存监督聚类结果
ggplot(data, aes(x=LUM, y=DCN, color = group, group = group)) +
geom_point(size = 3) +
geom_smooth(method=lm , color="red", fill="#69b3a2", se=TRUE) +
theme_classic() + theme(axis.title = element_text(size = 20,color = "black"),
axis.text = element_text(size = 20,color = "black"),
axis.line = element_line(size = 1),
axis.ticks = element_line(size = 1),
title = element_text(size = 20))
`geom_smooth()` using formula 'y ~ x'
Idents(ds2) <- ds2$Classification1
ds2_SMC2 <- subset(ds2, ident = "SMC2")
data2 <- FetchData(object = ds2_SMC2, vars = c("ACTA2", "TAGLN"))
rownames(data2) <- NULL
data2$group <- "unsup"
ggplot(data2, aes(x=ACTA2, y=TAGLN, color = group, group = group)) +
geom_point(size = 3,alpha=0.1) +
geom_smooth(method=lm , color="red", fill="#69b3a2", formula = 'y~x', se=TRUE) +
theme_classic() + theme(axis.title = element_text(size = 20,color = "black"),
axis.text = element_text(size = 20,color = "black"),
axis.line = element_line(size = 1),
axis.ticks = element_line(size = 1),
title = element_text(size = 20))
data2 <- FetchData(object = ds2_SMC2, vars = c("SOST", "DLX5"))
rownames(data2) <- NULL
data2$group <- "unsup"
ggplot(data2, aes(x=SOST, y=DLX5, color = group, group = group)) +
geom_point(size = 3,alpha=0.1) +
geom_smooth(method=lm , color="red", fill="#69b3a2", formula = 'y~x', se=TRUE) +
theme_classic() + theme(axis.title = element_text(size = 20,color = "black"),
axis.text = element_text(size = 20,color = "black"),
axis.line = element_line(size = 1),
axis.ticks = element_line(size = 1),
title = element_text(size = 20))
# dim(subset(ds2_SMC2, SOST>0))[2]
dim(subset(ds2_SMC2, `DLX5`>1))[2]
[1] 503
dim(subset(ds2_SMC2, `DLX5`>1&SOST>1))[2]
[1] 261
print("...")
[1] "..."
dim(subset(ds2_SMC2, DLX5>1))[2]
[1] 503
dim(subset(ds2_SMC2, `PRDM6`>1))[2]
[1] 208
dim(subset(ds2_SMC2, `PRDM6`>1&DLX5>1))[2]
[1] 126
dim(subset(ds2_SMC2, ACTA2>1))[2]
[1] 792
dim(subset(ds2_SMC2, TAGLN>1))[2]
[1] 959
dim(subset(ds2_SMC2, TAGLN>1&ACTA2>1))[2]
[1] 781
Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.